home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Risc World 3
/
Risc World 3.iso
/
SOFTWARE
/
ISSUE1
/
EASYC
/
!EasyC++
/
h
/
flex
< prev
next >
Wrap
Text File
|
1995-04-14
|
6KB
|
166 lines
/****************************************************************************
* This source file was written by Acorn Computers Limited. It is part of *
* the RISCOS library for writing applications in C for RISC OS. It may be *
* used freely in the creation of programs for Archimedes. It should be *
* used with Acorn's C Compiler Release 3 or later. *
* *
***************************************************************************/
/*
* Title : flex.h
* Purpose: provide memory allocation for interactive programs requiring
* large chunks of store. Such programs must respond to memory
* full errors.
*
*/
#ifndef __flex_h
#define __flex_h
#ifdef __cplusplus
extern "C" {
#endif
typedef void **flex_ptr;
/* ----------------------------- flex_alloc -------------------------------
* Description: Allocates n bytes of store, obtained from the Wimp.
*
* Parameters: flex_ptr anchor -- to be used to access allocated store
* int n -- number of bytes to be allocated
* Returns: 0 == failure, 1 == success
* Other Info: You should pass the & of a pointer variable as the first
* parameter. The allocated store MUST then be accessed
* indirectly, through this, ie. (*anchor)[0] ..(*anchor)[n]
* This is important since the allocated store may later be
* moved (it's a shifting heap!!). If there's not enough
* store returns zero leaving anchor unchanged.
*
*/
int flex_alloc(flex_ptr anchor, int n);
/* ------------------------------ flex_free -------------------------------
* Description: Frees the previously allocated store.
*
* Parameters: flex_ptr anchor -- pointer to allocated store
* Returns: void.
* Other Info: *anchor will be set to 0.
*
*/
void flex_free(flex_ptr anchor);
/* ------------------------------- flex_size ------------------------------
* Description: Informs caller of the number of bytes allocated
*
* Parameters: flex_ptr -- pointer to allocated store
* Returns: number of allocated bytes.
* Other Info: None.
*
*/
int flex_size(flex_ptr);
/* --------------------------- flex_extend --------------------------------
* Description: Extend ot truncate the store area to have a new size.
*
* Parameters: flex_ptr -- pointer to allocated store
* int newsize -- new size of store
* Returns: 0 == failure, 1 == success.
* Other Info: None.
*
*/
int flex_extend(flex_ptr, int newsize);
/* --------------------------- flex_midextend -----------------------------
* Description: Extend or truncate store, at any point.
*
* Parameters: flex_ptr -- pointer to allocated store
* int at -- location within the allocated store
* int by -- extent
* Returns: 0 == failure, 1 == success
* Other Info: If by is +ve, then store is extended, and locations above
* "at" are copied up by "by".
* If by is -ve, then store is reduced, and any bytes beyond
* "at" are copied down to "at"+"by".
*
*/
int flex_midextend(flex_ptr, int at, int by);
/* ---------------------------- flex_budge --------------------------------
* Description: Function to move flex store, when the C library needs
* to extend the heap.
*
* Parameters: int n -- number of bytes needed by C library
* void **a -- address of acquired store.
* Returns: amount of store acquired.
* Other Info: Don't call this function directly, but register it
* with the C library via:
* _kernel_register_slotextend(flex_budge);
* This will cause flex store to be moved up if the C
* library needs to extend the heap. Note that in this
* state, you can only rely on pointers into flex blocks
* across function calls which do not extend the stack and
* do not call malloc.
* The default state is flex_dont_budge, so, if required,
* this function should be registered AFTER calling
* flex_init().
*
*/
extern int flex_budge(int n, void **a);
/* -------------------------- flex_dont_budge -----------------------------
* Description: Function to refuse to move flex store, when the C library
* needs to extend the heap.
*
* Parameters: int n -- number of bytes needed by C library
* void **a -- address of acquired store.
* Returns: amount of store acquired (always 0).
* Other Info: Don't call this function directly, but register it
* with the C library via:
* _kernel_register_slotextend(flex_dont_budge);
* If the C library needs to extend the heap, flex will
* refuse to move. This means that you can rely on pointers
* into flex blocks across function calls.
* This is the DEFAULT state after flex_init().
*
*/
extern int flex_dont_budge(int n, void **a);
/* ---------------------------- flex_init ---------------------------------
* Description: Initialise store allocation module.
*
* Parameters: void.
* Returns: void.
* Other Info: Must be called before any other functions in this module.
*
*/
void flex_init(void);
#ifdef __cplusplus
}
#endif
#endif
/* end flex.h */